﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using ClassLibrary.Entitty;
using ClassLibrary.DAO;

public partial class MasterPage : System.Web.UI.MasterPage
{
    TblMenuItemDAO menuItemDAO = new TblMenuItemDAO(Global.CONNECTION_STRING);
    TblNoiDungDAO noidungDAO = new TblNoiDungDAO(Global.CONNECTION_STRING);
    TblMenuDAO menuDAO = new TblMenuDAO(Global.CONNECTION_STRING);
    TblContactDAO contactDAO = new TblContactDAO(Global.CONNECTION_STRING);

    //TblMenuItemDAO itemMenuDAO = new TblMenuItemDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
            loadTieuDeNoiDungTrang();
            LoadParenMenu();
            LoadImage();
            LoadContact();
        }
    }

    //load thong tin lien he
    private void LoadContact()
    {
        form.DataSource = contactDAO.GetAll();
        form.DataBind();
    }

 
    // Load Image
    private void LoadImage()
    {
          string id = Request.QueryString["id"];
          FormView1.DataSource = noidungDAO.getTieuDe_ByID(Global.ConvertToInt(id), 1);
          FormView1.DataBind();
    }

    private void LoadParenMenu()
    {
        reParentMenu.DataSource = menuDAO.GetAll();
        reParentMenu.DataBind();
    }

    private void loadTieuDeNoiDungTrang()
    {
        string id = Request.QueryString["id"];

        if (id == "8")
        {
            lbHead.Text = "our Team, our Strength";
        }
       
        if (id == "9")
        {
            lbHead.Text = "get in touch with us!";
            
        }
          
        else
        {
            lbHead.Text = "what we have we offer you";
        }

      
        if (id == null || Global.ConvertToInt(id) == 0)
        {
            DataTable noidung = noidungDAO.getTieuDe_ByID(1,1);
            foreach (DataRow dr in noidung.Rows)
            {
                lbtitle.Text = Server.HtmlDecode(dr["Noidung"].ToString());
            }
        }
        else
        {
            DataTable noidung = noidungDAO.getTieuDe_ByID(Global.ConvertToInt(id), 1);
            foreach (DataRow dr in noidung.Rows)
            {
                lbtitle.Text = Server.HtmlDecode(dr["Noidung"].ToString());
            }
        }
    }
    
    protected void reParentMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item ||
           e.Item.ItemType == ListItemType.AlternatingItem)
        {
            //int idCus = ((TblCustomers)Session[Global.SESSION_LOGGED_USER]).CustomerIndex;
            Repeater reChildMenu = (Repeater)e.Item.FindControl("reChildMenu");
            HiddenField hidIDMenuP = (HiddenField)e.Item.FindControl("hidIDMenuP");
            hidIDMenuP.Value = DataBinder.Eval(e.Item.DataItem, "ID").ToString();

            // DataTable dtParentMenu = ParentMenuDAO.GetParentMenuAll(idCus);
            // Lấy menu Cha

            DataTable menuCha = menuDAO.GetAll();

            string id = hidIDMenuP.Value;
            string idMenu = Request.QueryString["id"];
            if (reChildMenu != null)
            {

                reChildMenu.DataSource = menuItemDAO.GetMenuItem_ByName_ID(Global.ConvertToInt(id));
                reChildMenu.DataBind();
            }

        }
    }
}
